//
//  TheXXSystemAlert.m
//  TheXXCategory
//
//  Created by Logan.Fan on 16/8/29.
//  Copyright © 2016年 Logan. All rights reserved.
//

#import "TheXXSystemAlert.h"

@implementation TheXXSystemAlert

/**单个选项弹窗（Alert）*/
+ (void)alertFrom: (UIViewController *)viewController
       alertTitle: (NSString *)title
     defaultTitle: (NSString *)defaultTitle
       actionType: (UIAlertActionStyle)actionStyle
   defaultHandler: (void(^)(void))handler {
    
    UIAlertController *alertCtrl= [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *defaultAction= [UIAlertAction actionWithTitle:defaultTitle style:actionStyle handler:^(UIAlertAction * _Nonnull action) {
        !handler ? : handler();
    }];
//    [defaultAction setValue:[UIColor fontColorDarkGrey] forKey:@"titleTextColor"];
    [alertCtrl addAction:defaultAction];
    [viewController presentViewController:alertCtrl animated:YES completion:nil];
}

/**标题+消息 两个选项弹窗（Alert）*/
+ (void)alertFromVC: (UIViewController *)viewController
         alertTitle: (NSString *)alertTitle
       alertMessage: (NSString *)alertMessage
        cancelTitle: (NSString *)cancelTitle
   cancelActionType: (UIAlertActionStyle)cancelType
       confirmTitle: (NSString *)destructiveTitle
  confirmActionType: (UIAlertActionStyle)confirmType
      cancelHandler: (void(^)(void))cancelHandler
 destructiveHandler: (void(^)(void))destructiveHandler {
    UIAlertController *alertCtl = [UIAlertController alertControllerWithTitle:alertTitle message:alertMessage preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:cancelTitle style:cancelType handler:^(UIAlertAction * _Nonnull action) {
        !cancelHandler ? : cancelHandler();
    }];
//    [actionCancel setValue:[UIColor fontColorDarkGrey] forKey:@"titleTextColor"];
    UIAlertAction *actionDestructive = [UIAlertAction actionWithTitle:destructiveTitle style:confirmType handler:^(UIAlertAction * _Nonnull action) {
        !destructiveHandler ? : destructiveHandler();
    }];
//    [actionDestructive setValue:[UIColor fontColorDarkGrey] forKey:@"titleTextColor"];
    [alertCtl addAction:actionCancel];
    [alertCtl addAction:actionDestructive];
    [viewController presentViewController:alertCtl animated:YES completion:nil];
}

/**标题+消息 两个选项弹窗（ActionSheet）*/
+ (void)actionSheetFromVC :(UIViewController *)viewController
               alertTitle :(NSString *)alertTitle
             alertMessage :(NSString *)alertMessage
              cancelTitle :(NSString *)cancelTitle
         cancelActionType :(UIAlertActionStyle)cancelType
             confirmTitle :(NSString *)destructiveTitle
        confirmActionType :(UIAlertActionStyle)confirmType
            cancelHandler :(void(^)(void))cancelHandler
       destructiveHandler :(void(^)(void))destructiveHandler {
    
    UIAlertController *alertCtl = [UIAlertController alertControllerWithTitle:alertTitle message:alertMessage preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:cancelTitle style:cancelType handler:^(UIAlertAction * _Nonnull action) {
        !cancelHandler ? : cancelHandler();
    }];
//    [actionCancel setValue:[UIColor fontColorDarkGrey] forKey:@"titleTextColor"];
    UIAlertAction *actionDestructive = [UIAlertAction actionWithTitle:destructiveTitle style:confirmType handler:^(UIAlertAction * _Nonnull action) {
        !destructiveHandler ? : destructiveHandler();
    }];
//    [actionDestructive setValue:[UIColor fontColorDarkGrey] forKey:@"titleTextColor"];
    [alertCtl addAction:actionCancel];
    [alertCtl addAction:actionDestructive];
    [viewController presentViewController:alertCtl animated:YES completion:nil];
}

@end
